<?php

/**
 * This is the model class for table "rs_service".
 *
 * The followings are the available columns in table 'rs_service':
 * @property integer $id
 * @property string $name
 * @property string $alias
 * @property integer $business_id
 * @property integer $category_id
 * @property string $create_time
 * @property string $update_time
 * @property integer $created_by
 * @property integer $updated_by
 * @property string $description
 * @property integer $status
 * @property string $price
 * @property string $gender
 * @property string $duration
 */
class Service extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Service the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'rs_service';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('business_id, category_id, created_by, updated_by, status', 'numerical', 'integerOnly'=>true),
			array('name, alias', 'length', 'max'=>255),
			array('price', 'length', 'max'=>10),
			array('gender', 'length', 'max'=>6),
			array('duration', 'length', 'max'=>125),
			array('create_time, update_time, description', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, alias, business_id, category_id, create_time, update_time, created_by, updated_by, description, status, price, gender, duration', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            //'rsAppointments' => array(self::MANY_MANY, 'Appointment', 'rs_appointment_service(service_id, appointment_id)'),
            'createdBy' => array(self::BELONGS_TO, 'User', 'created_by'),
            'serviceOwner' => array(self::BELONGS_TO, 'Business', 'business_id'),
        );
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'alias' => 'Alias',
			'business_id' => 'Business',
			'category_id' => 'Category',
			'create_time' => 'Create Time',
			'update_time' => 'Update Time',
			'created_by' => 'Created By',
			'updated_by' => 'Updated By',
			'description' => 'Description',
			'status' => 'Status',
			'price' => 'Price',
			'gender' => 'Gender',
			'duration' => 'Duration',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('alias',$this->alias,true);
		$criteria->compare('business_id',$this->business_id);
		$criteria->compare('category_id',$this->category_id);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('update_time',$this->update_time,true);
		$criteria->compare('created_by',$this->created_by);
		$criteria->compare('updated_by',$this->updated_by);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('price',$this->price,true);
		$criteria->compare('gender',$this->gender,true);
		$criteria->compare('duration',$this->duration,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}